<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="test1" >
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">姓名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入修改后的用户名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码：</label>
        <div class="layui-input-block">
            <input type="number" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入新密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别：</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked="">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">家乡：</label>
        <div class="layui-input-block">
            <input type="text" name="home" placeholder="请输入家乡" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">修改用户</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    //获取要修改的对象
    var obj=JSON.parse(localStorage.getItem("user"));
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;
        //为表单赋值
        form.val("test1",obj);
        // $("#img1")[0].src=obj.headurl;
        // //执行实例
        // var uploadInst = upload.render({
        //     elem: '#test1' //绑定元素
        //     ,url: '/api/image/uploadimg.do' //上传接口
        //     ,done: function(res){
        //         //上传完毕回调
        //         if(res.code==0){
        //             //成功
        //             $("#ip1").val(res.data);
        //             //把jquery对象转换为js对象（dom）
        //             $("#img1")[0].src=res.data;
        //         }else {
        //             layer.msg("亲，上传失败！");
        //         }
        //     }
        //     ,error: function(){
        //         //请求异常回调
        //     }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //新增用户 Ajax 请求接口
            $.post('/api/user/update.do',data.field,function (res){
                if(res.code==0){
                    layer.msg("修改成功");
                    location.href="usertable.html";
                }else {
                    layer.msg("亲。修改失败！");
                }
            })
            return false;
        });
    });
</script>
</body>
</html>